package com.imooc.mall.common;

import com.google.common.collect.Sets;
import com.imooc.mall.exception.ImoocMallException;
import com.imooc.mall.exception.ImoocMallExceptionEnum;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;


import java.util.Set;

/**
 * 常量类
 */
@Component
public class Constant {

    public static void main(String[] args) {
        System.out.println("aaa");
    }


    // // //
    public static final String IMOOC_MALL_USER="imooc_mall_user";

    //盐值
    public static final String SALT="EDKFHSDKLJFHDALRJEIO[][][";

    //文件存放地址
    public static  String FILE_UPLOAD_DIR;
    @Value("${file.upload.dir}")
    public void setFileUploadDir(String fileUploadDir){
        FILE_UPLOAD_DIR=fileUploadDir;
    // aaaaaaaaaaaaaaaaaaaa
        // bbbbbbbbbb
    }

    public interface productListOrderBy{
        Set<String > PRICE_ASC_DESC = Sets.newHashSet("price desc","price acs");
    }

    //商品上下架状态的枚举
    public interface SaleStatus{
        int NOT_SALE=0;
        int SALT=1;
    }

    //商品是否被选中状态的枚举
    public interface Cart{
        int NO_CHECKED=0;
        int CHECKED=1;
    }

    //用户支付阶段
    public enum OrderStatusEnum{

        CANCELED(0,"用户已取消"),
        NOT_PAID(10,"用户未付款"),
        PAID(20,"用户已付款"),
        DELIVERED(30,"已发货"),
        FINISHED(40,"交易已完成"),
        ;

        private int code;
        private String value;

        OrderStatusEnum(int code, String value) {
            this.code = code;
            this.value = value;
        }
        public int getCode() {
            return code;
        }

        public void setCode(int code) {
            this.code = code;
        }

        public String getValue() {
            return value;
        }

        public void setValue(String value) {
            this.value = value;
        }


        public static OrderStatusEnum codeOf(Integer code){
         for (OrderStatusEnum orderStatusEnum:values()){
                if (orderStatusEnum.code==code){
                    return orderStatusEnum;
                }
         }
         throw new ImoocMallException(ImoocMallExceptionEnum.NOT_ENOUGH);
            }
        }
    }
